using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using DevComponents.DotNetBar;
using System.Drawing;
using System.Windows.Forms;
using System.IO;

namespace Shine.Framework
{
    [Guid("37dd037f-b035-444b-89dc-d20431089a38")]
    public class StatusBarClass : IStatusBar
    {
        private IAnimationProgressor m_ProgressAnimation = null;
        private IStepProgressor m_ProgressBar = null;

        private Bar m_StatusBar;
        private LabelItem m_Message;
        private ControlContainerItem m_Animation;
        private ProgressBarItem m_Progress;
        private LabelItem m_Coordinate;

        #region Attribute
        public LabelItem Message
        {
            get
            {
                return this.m_Message;
            }
        }
        //public ControlContainerItem Animation
        //{
        //    get
        //    {
        //        return this.m_Animation;
        //    }
        //}
        public ProgressBarItem Progress
        {
            get
            {
                return this.m_Progress;
            }
        }
        //public LabelItem Coordinate
        //{
        //    get
        //    {
        //        return this.m_Coordinate;
        //    }
        //}
        public Bar StatusBar
        {
            set
            {
                m_StatusBar = value;

                if (m_StatusBar.Items.Contains("progressBar"))
                    m_Progress = m_StatusBar.Items["progressBar"] as ProgressBarItem;
            }
            get
            {
                return m_StatusBar;
            }
        }

        public int ItemCount
        {
            get
            {
                return m_StatusBar.Items.Count;
            }
        }

        public bool Visible
        {
            get
            {
                return m_StatusBar.Visible;
            }
            set
            {
                m_StatusBar.Visible = value;
            }
        }

        //public IAnimationProgressor ProgressAnimation
        //{
        //    get
        //    {
        //        return m_ProgressAnimation;
        //    }
        //}

        public IStepProgressor ProgressBar
        {
            get
            {
                return m_ProgressBar;
            }
        }
        #endregion

        public StatusBarClass()
        {
            //this.m_StatusBar = new DevComponents.DotNetBar.Bar();
            //this.m_Message = new DevComponents.DotNetBar.LabelItem();
            //this.m_Animation = new DevComponents.DotNetBar.ControlContainerItem();
            //this.m_Progress = new DevComponents.DotNetBar.ProgressBarItem();
            //this.m_Coordinate = new DevComponents.DotNetBar.LabelItem();
            //// 
            //// m_StatusBar
            //// 
            //this.m_StatusBar.AccessibleDescription = "DotNetBar Bar (m_StatusBar)";
            //this.m_StatusBar.AccessibleName = "DotNetBar Bar";
            //this.m_StatusBar.AccessibleRole = System.Windows.Forms.AccessibleRole.StatusBar;
            //this.m_StatusBar.Dock = System.Windows.Forms.DockStyle.Bottom;
            //this.m_StatusBar.GrabHandleStyle = DevComponents.DotNetBar.eGrabHandleStyle.ResizeHandle;
            //this.m_StatusBar.Items.AddRange(new DevComponents.DotNetBar.BaseItem[] {
            //this.m_Message,
            //this.m_Coordinate,
            //this.m_Animation,
            //this.m_Progress
            //});
            //this.m_StatusBar.Location = new System.Drawing.Point(0, 902);
            //this.m_StatusBar.Name = "m_StatusBar";
            //this.m_StatusBar.Size = new System.Drawing.Size(1264, 24);
            //this.m_StatusBar.Stretch = true;
            //this.m_StatusBar.Style = DevComponents.DotNetBar.eDotNetBarStyle.VS2005;
            //this.m_StatusBar.TabIndex = 8;
            //this.m_StatusBar.TabStop = false;
            //this.m_StatusBar.Text = "m_StatusBar";


            //// 
            //// m_Message
            //// 
            //this.m_Message.Name = "m_Message";
            ////this.m_Message.Width = m_StatusBar.Width * 2 / 5;
            //this.m_Message.Stretch = false;
            //this.m_Message.Height = 24;//ym
            //// 
            //// m_Animation
            //// 
            //this.m_Animation.AllowItemResize = false;
            //this.m_Animation.BeginGroup = true;
            //this.m_Animation.Control = null;
            //this.m_Animation.MenuVisibility = DevComponents.DotNetBar.eMenuVisibility.VisibleAlways;
            //this.m_Animation.Name = "m_Animation";
            //this.m_Animation.ShowSubItems = false;
            //this.m_Animation.Tag = "  ";
            //this.m_Animation.Size = new Size(24, 24);//ym
            //this.m_Animation.Visible = false;
            //this.m_Animation.Stretch = false;
            //// 
            //// m_Progress
            //// 
            //this.m_Progress.BeginGroup = true;
            //this.m_Progress.ChunkGradientAngle = 0F;
            //this.m_Progress.MenuVisibility = DevComponents.DotNetBar.eMenuVisibility.VisibleAlways;
            //this.m_Progress.Name = "m_Progress";
            //this.m_Progress.RecentlyUsed = false;
            ////this.m_Progress.Width = m_StatusBar.Width  / 5;
            ////this.m_Progress.Height = 24;
            //this.m_Progress.Stretch = false;
            //// 
            //// m_Coordinate
            //// 
            //this.m_Coordinate.BeginGroup = true;
            //this.m_Coordinate.ItemAlignment = eItemAlignment.Far;
            //this.m_Coordinate.Name = "m_Coordinate";
            //this.m_Coordinate.Stretch = false;
            //this.m_Coordinate.Height = 24;
            ////this.m_Coordinate.Width = m_StatusBar.Width*2/5;
        }

        public string get_Message(int item)
        {
            if (item < m_StatusBar.Items.Count)
                return m_StatusBar.Items[item].Text;
            else
                return "";
        }

        public void set_Message(int item, string Message)
        {
            if (item < m_StatusBar.Items.Count)
            m_StatusBar.Items[item].Text = Message;
        }

        //public void HideProgressAnimation()
        //{
        //    m_Animation.Visible = false;
        //}

        public void HideProgressBar()
        {
            //m_Progress.Width = 0;
            m_Progress.Visible = false;
            set_Message(2, "");
            Application.DoEvents();
        }

        //public void PlayProgressAnimation(bool playAnim)
        //{
        //    m_Animation.Visible = playAnim;
        //}

        //public void ShowProgressAnimation(string Message, string animationPath)
        //{
        //    m_Animation.KeyTips = Message;
        //    PictureBox pPicturebox = new PictureBox();
        //    pPicturebox.Height = 18;
        //    pPicturebox.Width = 18;
        //    if (animationPath == null || animationPath == "" || !File.Exists(animationPath))
        //        pPicturebox.Image = Shine.Framework.Properties.Resources.Animation;
        //    else
        //        pPicturebox.Image = Image.FromFile(animationPath);
        //    m_Animation.Control = pPicturebox;
        //    m_Animation.Visible = true;
        //}

        public void ShowProgressBar(string message, int min, int max, int Step)
        {
            try
            {
                m_Progress.Visible = true;
                Application.DoEvents();
                m_Progress.ProgressType = eProgressItemType.Standard;
                m_Progress.ColorTable = eProgressBarItemColor.Normal;
                m_Progress.Minimum = min;
                m_Progress.Maximum = max;
                m_Progress.Step = Step;
                m_Progress.Value = min;
                set_Message(2, message);
            }
            catch
            {
            }
        }
        public void ShowProgressBar(string message)
        {
            try
            {
                if (m_Progress.Visible) return;
                m_Progress.Visible = true;
                Application.DoEvents();
                m_Progress.ChunkColor = Color.FromArgb(((int)(((byte)(59)))), ((int)(((byte)(97)))), ((int)(((byte)(156)))));
                m_Progress.ChunkColor2 = Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(207)))), ((int)(((byte)(139)))));
                m_Progress.ChunkGradientAngle = 90F;
                m_Progress.ProgressType = eProgressItemType.Marquee;
                set_Message(2, message);
            }catch
            {
            }
        }
        public void StepProgressBar()
        {
            if (m_Progress != null && m_Progress.Value<m_Progress.Maximum)
                m_Progress.Value++;
        }
    }
}
